package cn.IT.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * Topic entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "topic", catalog = "itsupport")

public class Topic implements java.io.Serializable {

	// Fields

	private Integer topicId;
	private Type type;
	private User userByToUserId;
	private User userByUserId;
	private String title;
	private String content;
	private Integer replyCount;
	private Integer isReaded;
	private Date createdOn;
//	private Set<Reply> replies = new HashSet<Reply>(0);

	// Constructors

	/** default constructor */
	public Topic() {
	}

	/** minimal constructor */
	public Topic(Type type, User userByUserId, String title, Integer replyCount, Integer isReaded, Date createdOn) {
		this.type = type;
		this.userByUserId = userByUserId;
		this.title = title;
		this.replyCount = replyCount;
		this.isReaded = isReaded;
		this.createdOn = createdOn;
	}

//	/** full constructor */
//	public Topic(Type type, User userByToUserId, User userByUserId, String title, String content, Integer replyCount,
//			Integer isReaded, Date createdOn, Set<Reply> replies) {
//		this.type = type;
//		this.userByToUserId = userByToUserId;
//		this.userByUserId = userByUserId;
//		this.title = title;
//		this.content = content;
//		this.replyCount = replyCount;
//		this.isReaded = isReaded;
//		this.createdOn = createdOn;
//		this.replies = replies;
//	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "topicId", unique = true, nullable = false)

	public Integer getTopicId() {
		return this.topicId;
	}

	public void setTopicId(Integer topicId) {
		this.topicId = topicId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "typeId", nullable = false)

	public Type getType() {
		return this.type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "toUserId")
	@NotFound(action=NotFoundAction.IGNORE)
	public User getUserByToUserId() {
		return this.userByToUserId;
	}

	public void setUserByToUserId(User userByToUserId) {
		this.userByToUserId = userByToUserId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "userId", nullable = false)

	public User getUserByUserId() {
		return this.userByUserId;
	}

	public void setUserByUserId(User userByUserId) {
		this.userByUserId = userByUserId;
	}

	@Column(name = "title", nullable = false)

	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "content", length = 65535)

	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "replyCount", nullable = false)

	public Integer getReplyCount() {
		return this.replyCount;
	}

	public void setReplyCount(Integer replyCount) {
		this.replyCount = replyCount;
	}

	@Column(name = "isReaded", nullable = false)

	public Integer getIsReaded() {
		return this.isReaded;
	}

	public void setIsReaded(Integer isReaded) {
		this.isReaded = isReaded;
	}

	@Column(name = "createdOn", nullable = false, length = 10)

	public Date getCreatedOn() {
		return this.createdOn;
	}

	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

//	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "topic")
//
//	public Set<Reply> getReplies() {
//		return this.replies;
//	}
//
//	public void setReplies(Set<Reply> replies) {
//		this.replies = replies;
//	}

}